package com.qf.android.huihui.adapter.shopping;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.qf.android.huihui.R;
import com.qf.android.huihui.bean.show.shoppingbottom.HotBusiness;
import com.qf.android.huihui.common.IClickListern;

import java.util.List;

/**
 * Created by 韩爽 on 2017/1/12.
 */

public class ShoppingDmailAdapter extends ShoppingBaseAdapter {
    private List<HotBusiness.DataBean.DmailBean.ListBean> list;
    private Context context;

    public ShoppingDmailAdapter(List<HotBusiness.DataBean.DmailBean.ListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.fragment_shopping_dmail_item,parent,false);
        MyHolder myHolder=new MyHolder(view,listern);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        HotBusiness.DataBean.DmailBean.ListBean listBean = list.get(position);
        Glide.with(context).load(listBean.getImageUrl()).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL).into(((MyHolder)holder).imageView);
        ((MyHolder)holder).itemView.setTag(listBean.getUrl());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    public void setMyClickListener(IClickListern listener) {
        this.listern=listener;
    }

    public class MyHolder extends ShoppingBaseAdapter.MyHolder {
        private ImageView imageView;
        private IClickListern listern;
        public MyHolder(View itemView, IClickListern listern) {
            super(itemView, listern);
            this.listern=listern;
            imageView= (ImageView) itemView.findViewById(R.id.fragment_shopping_dmail_item_imageview);
        }

        @Override
        public void onClick(View v) {
            if(listern!=null){
                listern.OnItemClick(v,(String)v.getTag());
            }
        }
    }
}
